﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using QuanLyKhachSan.BusinessLogic;
using QuanLyKhachSan.BusinessObject;
using QuanLyKhachSan.DataAccess;

namespace QuanLyKhachSan
{
    public partial class frmTinhTien : Form
    {
        private NhanVienBL nvBL = new NhanVienBL();
        private KhachHangBL khBL = new KhachHangBL();
        private PhongBL pBL = new PhongBL();
        private PhieuThuePhongBL ptpBL = new PhieuThuePhongBL();
        private PhieuThuePhongBO ptpBO = new PhieuThuePhongBO();
      //private string maPhong;
        public frmTinhTien()
        {
            InitializeComponent();
        }
        public static string Tien;
        private void frmTinhTien_Load(object sender, EventArgs e)
        {
            txtTienPhong.Text = Tien;
            cboMaNhanVien.DataSource = nvBL.LayDanhSachNhanVien();
            cboMaNhanVien.DisplayMember = "TenNhanVien";
            cboMaNhanVien.ValueMember = "MaNhanVien";

            cboMaKhachHang.DataSource = khBL.LayDSKhachHang();
            cboMaKhachHang.DisplayMember = "TenKhachHang";
            cboMaKhachHang.ValueMember = "MaKhachHang";

            cboMaPhong.DataSource = pBL.LayDSThuePhongTrong();
            cboMaPhong.DisplayMember = "TenPhong";
            cboMaPhong.ValueMember = "MaPhong";

            cboTinhTrang.DataSource = ptpBL.LayTinhTrangThanhToan();
            cboTinhTrang.DisplayMember = "TTThanhToan";
            cboTinhTrang.ValueMember = "TinhTrang";
        }

        //lấy thông tin phiếu thuê phòng
        private PhieuThuePhongBO LayTTPTP()
        {
            PhieuThuePhongBO ptpBO = new PhieuThuePhongBO();
            ptpBO.MaThuePhong = txtMaThuePhong.Text;
            ptpBO.MaNhanVien = cboMaNhanVien.SelectedValue.ToString();
            ptpBO.MaKhachHang = cboMaKhachHang.SelectedValue.ToString();
            ptpBO.MaPhong = cboMaPhong.SelectedValue.ToString();
            ptpBO.NgayThue = Convert.ToDateTime(dtTimePickerNgayThue.Value.ToShortDateString());
            ptpBO.NgayTra = Convert.ToDateTime(dtTimePickerNgayTra.Value.ToShortDateString());
            ptpBO.TienPhong = int.Parse(txtTienPhong.Text);
            ptpBO.TinhTrang = (cboTinhTrang.SelectedValue.ToString() == "True") ? 1 : 0;
            ptpBO.TienPhong = int.Parse(txtTienPhong.Text);
            return ptpBO;

        }

        public void Load_Edit(PhieuThuePhongBO ptpBO)
        {
            txtMaThuePhong.Text = ptpBO.MaThuePhong.ToString();
            cboMaNhanVien.Text = ptpBO.MaNhanVien.ToString();
            cboMaKhachHang.Text = ptpBO.MaKhachHang.ToString();
            //cboMaLoaiPhong.Text = pBO.MaLoaiPhong.ToString();
            cboMaPhong.Text = ptpBO.MaPhong.ToString();
            // cboTinhTrang.Text = pBO.TinhTrang.ToString();
            dtTimePickerNgayThue.Text = ptpBO.NgayThue.ToString();

        }
        public void Load_TT(PhieuThuePhongBO ptpBO)
        {
            txtMaThuePhong.Text = ptpBO.MaThuePhong.ToString();
            cboMaNhanVien.Text = ptpBO.MaNhanVien.ToString();
            cboMaKhachHang.Text = ptpBO.MaKhachHang.ToString();
            //cboMaLoaiPhong.Text = pBO.MaLoaiPhong.ToString();
            cboMaPhong.Text = ptpBO.MaPhong.ToString();
            // cboTinhTrang.Text = pBO.TinhTrang.ToString();
            dtTimePickerNgayThue.Text = ptpBO.NgayThue.ToString();
            
            //int donGia = LoaiPhongBL.LayTien(PhongBL.LayMaLoaiPhong(maPhong));
            //TimeSpan dt = new TimeSpan();
            //dt = DateTime.Now - ptpBO.NgayThue;
            ////MessageBox.Show(dt.Days.ToString());
            //int tong = dt.Days * donGia;
            //txtTienPhong.Text = tong.ToString();

        }
        private void button1_Click(object sender, EventArgs e)
        {
            frmPhieuThuePhong fptp = new frmPhieuThuePhong();
            fptp.Show();
            this.Close();
        }

        private void btnTinhTien_Click(object sender, EventArgs e)
        {
            
        }

        public delegate void DuLieuTruyenVe(PhieuThuePhongBO PTP);
        public DuLieuTruyenVe DuLieu;

        private void btnLuu_Click(object sender, EventArgs e)
        {
            PhieuThuePhongBO ptp = LayTTPTP();
           


                ptpBL.ThanhToan(ptp);

                this.Close();
           
            if (DuLieu != null)
            {
                DuLieu(ptp);
            }
        }
    }
}
